package com.fr.dialog.core;

import com.fr.base.DefaultValues;
import com.fr.base.FRContext;
import com.fr.base.Inter;
import com.fr.cell.core.GUICoreUtils;
import com.fr.cell.core.layout.LayoutFactory;
import com.fr.report.cellElement.TextFormat;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.Document;

public class FormatPane extends JPanel
{
  private Format format;
  ActionListener radioActionListener = new ActionListener(this)
  {
    private final FormatPane this$0;

    public void actionPerformed()
    {
      Object localObject = paramActionEvent.getSource();
      FormatPane.access$000(this.this$0).setEnabled(true);
      FormatPane.access$000(this.this$0).setEditable(true);
      FormatPane.access$100(this.this$0).setEnabled(true);
      String[] arrayOfString = FormatPane.None_Array;
      if (localObject.equals(FormatPane.access$200(this.this$0)))
      {
        FormatPane.access$000(this.this$0).setEnabled(false);
        FormatPane.access$000(this.this$0).setEditable(false);
        FormatPane.access$000(this.this$0).setText("");
        FormatPane.access$100(this.this$0).setEnabled(false);
        arrayOfString = FormatPane.None_Array;
      }
      else if (localObject.equals(FormatPane.access$300(this.this$0)))
      {
        arrayOfString = FormatPane.Number_Array;
      }
      else if (localObject.equals(FormatPane.access$400(this.this$0)))
      {
        arrayOfString = FormatPane.Currency_Array;
      }
      else if (localObject.equals(FormatPane.access$500(this.this$0)))
      {
        arrayOfString = FormatPane.Percent_Array;
      }
      else if (localObject.equals(FormatPane.access$600(this.this$0)))
      {
        arrayOfString = FormatPane.Scientfic_Array;
      }
      else if (localObject.equals(FormatPane.access$700(this.this$0)))
      {
        arrayOfString = FormatPane.Date_Array;
      }
      else if (localObject.equals(FormatPane.access$800(this.this$0)))
      {
        arrayOfString = FormatPane.Time_Array;
      }
      else if (localObject.equals(FormatPane.access$900(this.this$0)))
      {
        FormatPane.access$000(this.this$0).setEnabled(false);
        FormatPane.access$000(this.this$0).setEditable(false);
        FormatPane.access$000(this.this$0).setText("");
        FormatPane.access$100(this.this$0).setEnabled(false);
        arrayOfString = FormatPane.Text_Array;
      }
      DefaultListModel localDefaultListModel = (DefaultListModel)FormatPane.access$100(this.this$0).getModel();
      localDefaultListModel.removeAllElements();
      for (int i = 0; i < arrayOfString.length; ++i)
        localDefaultListModel.addElement(arrayOfString[i]);
      String str1 = FormatPane.access$000(this.this$0).getText();
      if ((((str1 == null) || (str1.length() <= 0))) && (localDefaultListModel.size() > 0))
      {
        String str2 = null;
        if (FormatPane.access$1000(this.this$0) instanceof DecimalFormat)
          str2 = ((DecimalFormat)FormatPane.access$1000(this.this$0)).toPattern();
        else if (FormatPane.access$1000(this.this$0) instanceof SimpleDateFormat)
          str2 = ((SimpleDateFormat)FormatPane.access$1000(this.this$0)).toPattern();
        if ((!(FormatPane.access$1000(this.this$0) instanceof TextFormat)) || (str2 != null))
          FormatPane.access$100(this.this$0).setSelectedValue(str2, true);
        else
          FormatPane.access$100(this.this$0).setSelectedIndex(0);
      }
    }
  };
  DocumentListener patternTextDocumentListener = new DocumentListener(this)
  {
    private final FormatPane this$0;

    public void insertUpdate()
    {
      FormatPane.access$1100(this.this$0);
    }

    public void removeUpdate()
    {
      FormatPane.access$1100(this.this$0);
    }

    public void changedUpdate()
    {
      FormatPane.access$1100(this.this$0);
    }
  };
  ListSelectionListener patternListSelectionListener = new ListSelectionListener(this)
  {
    private final FormatPane this$0;

    public void valueChanged()
    {
      FormatPane.access$000(this.this$0).setText((String)FormatPane.access$100(this.this$0).getSelectedValue());
    }
  };
  private JLabel sampleLabel;
  private JRadioButton nullRadioButton;
  private JRadioButton numberRadioButton;
  private JRadioButton currencyRadioButton;
  private JRadioButton percentRadioButton;
  private JRadioButton scientificRadioButton;
  private JRadioButton dateRadioButton;
  private JRadioButton timeRadioButton;
  private JRadioButton textRadioButton;
  private JTextField patternTextField = null;
  private JList patternList = null;
  static double DoubleValue = 12345.678900000001D;
  static String[] None_Array = new String[0];
  static String[] Number_Array = { "0", "0.00", "#0.0#", "#,##0", "#,##0.00" };
  static String[] Currency_Array = { "¤0", "¤0.00", "¤#,##0", "¤#,##0.0", "¤#,##0.00", "¤#,##0;¤-#,##0", "¤#,##0.00;¤-#,##0.00", "¤#,##0.00;(¤#,##0.00)", "$#,##0;($#,##0)", "$#,##0.00;($#,##0.00)", "#,##0;-#,##0", "#,##0;[Red]-#,##0", "#,##0.00;-#,##0.00" };
  static String[] Percent_Array = { "0%", "0.0%", "0.00%", "0.000%", "0.0000%" };
  static String[] Scientfic_Array = { "0.00E00", "##0.0E0" };
  static String[] Date_Array = { "MM/dd/yyyy", "yyyy-MM-dd", "EEEEE, MMMMM dd, yyyy", "MMMM d, yyyy", "MM/d/yy", "d-MMM-yy", "MM.d.yyyy", "MMM. d, yyyy", "d MMMMM yyyy", "MMMMM yy", "MM-yy", "yyyy-M-d", "d-MMM", "M-d-yy" };
  static String[] Time_Array = { "h:mm", "H:mm", "h:mm:ss", "H:mm:ss", "hh:mm", "HH:mm", "mm:ss", "mm:ss.0", "[h]:mm:ss", "[H]:mm:ss", "yyyy-M-d h:mm", "yyyy-M-d H:mm", "MM/dd/yyyy hh:mm:ss", "MM/dd/yyyy HH:mm:ss", "MM/dd/yyyy hh:mm:ss a", "MM/dd/yyyy HH:mm:ss a", "MM/dd/yyyy h:mm a", "MM/dd/yyyy H:mm a", "h:mm:ss a", "HH:mm:ss a", "h:mm:ss a, z", "HH:mm:ss a, z" };
  static String[] Text_Array = new String[0];

  public FormatPane()
  {
    initComponents();
  }

  protected void initComponents()
  {
    setLayout(new BorderLayout(4, 0));
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    JPanel localJPanel1 = new JPanel();
    add(localJPanel1, "North");
    localJPanel1.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("StyleFormat-Sample"), null));
    localJPanel1.setLayout(LayoutFactory.createBorderLayout());
    this.sampleLabel = new JLabel("" + DoubleValue);
    localJPanel1.add(this.sampleLabel, "Center");
    this.sampleLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4));
    this.sampleLabel.setHorizontalAlignment(0);
    this.sampleLabel.setFont(FRContext.getDefaultValues().getFRFont());
    JPanel localJPanel2 = new JPanel();
    add(localJPanel2, "West");
    localJPanel2.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("StyleFormat-Category"), null));
    localJPanel2.setLayout(new GridLayout(8, 1, 4, 4));
    this.nullRadioButton = new JRadioButton(Inter.getLocText("StyleFormat-None"));
    this.nullRadioButton.setMnemonic('o');
    this.numberRadioButton = new JRadioButton(Inter.getLocText("Number"));
    this.numberRadioButton.setMnemonic('N');
    this.currencyRadioButton = new JRadioButton(Inter.getLocText("StyleFormat-Currency"));
    this.currencyRadioButton.setMnemonic('C');
    this.percentRadioButton = new JRadioButton(Inter.getLocText("StyleFormat-Percent"));
    this.percentRadioButton.setMnemonic('P');
    this.scientificRadioButton = new JRadioButton(Inter.getLocText("StyleFormat-Scientific"));
    this.scientificRadioButton.setMnemonic('S');
    this.dateRadioButton = new JRadioButton(Inter.getLocText("StyleFormat-Date"));
    this.dateRadioButton.setMnemonic('D');
    this.timeRadioButton = new JRadioButton(Inter.getLocText("StyleFormat-Time"));
    this.timeRadioButton.setMnemonic('I');
    this.textRadioButton = new JRadioButton(Inter.getLocText("StyleFormat-Text"));
    this.textRadioButton.setMnemonic('T');
    this.nullRadioButton.addActionListener(this.radioActionListener);
    this.numberRadioButton.addActionListener(this.radioActionListener);
    this.currencyRadioButton.addActionListener(this.radioActionListener);
    this.percentRadioButton.addActionListener(this.radioActionListener);
    this.scientificRadioButton.addActionListener(this.radioActionListener);
    this.dateRadioButton.addActionListener(this.radioActionListener);
    this.timeRadioButton.addActionListener(this.radioActionListener);
    this.textRadioButton.addActionListener(this.radioActionListener);
    ButtonGroup localButtonGroup = new ButtonGroup();
    localButtonGroup.add(this.nullRadioButton);
    localButtonGroup.add(this.numberRadioButton);
    localButtonGroup.add(this.currencyRadioButton);
    localButtonGroup.add(this.percentRadioButton);
    localButtonGroup.add(this.scientificRadioButton);
    localButtonGroup.add(this.dateRadioButton);
    localButtonGroup.add(this.timeRadioButton);
    localButtonGroup.add(this.textRadioButton);
    localJPanel2.add(createRadioCenterPane(this.nullRadioButton));
    localJPanel2.add(createRadioCenterPane(this.numberRadioButton));
    localJPanel2.add(createRadioCenterPane(this.currencyRadioButton));
    localJPanel2.add(createRadioCenterPane(this.percentRadioButton));
    localJPanel2.add(createRadioCenterPane(this.scientificRadioButton));
    localJPanel2.add(createRadioCenterPane(this.dateRadioButton));
    localJPanel2.add(createRadioCenterPane(this.timeRadioButton));
    localJPanel2.add(createRadioCenterPane(this.textRadioButton));
    JPanel localJPanel3 = new JPanel();
    add(localJPanel3, "Center");
    localJPanel3.setBorder(BorderFactory.createEmptyBorder(4, 0, 2, 0));
    localJPanel3.setLayout(new BorderLayout(0, 3));
    this.patternTextField = new JTextField();
    localJPanel3.add(this.patternTextField, "North");
    this.patternTextField.getDocument().addDocumentListener(this.patternTextDocumentListener);
    this.patternList = new JList(new DefaultListModel());
    localJPanel3.add(new JScrollPane(this.patternList), "Center");
    this.patternList.addListSelectionListener(this.patternListSelectionListener);
    this.nullRadioButton.setSelected(true);
    applyRadioActionListener(this.nullRadioButton);
  }

  private JPanel createRadioCenterPane(JRadioButton paramJRadioButton)
  {
    JPanel localJPanel = new JPanel();
    localJPanel.setLayout(new FlowLayout(0, 0, 0));
    localJPanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
    localJPanel.add(paramJRadioButton);
    return localJPanel;
  }

  public void populate(Format paramFormat)
  {
    this.format = paramFormat;
    if (paramFormat == null)
    {
      this.nullRadioButton.setSelected(true);
      applyRadioActionListener(this.nullRadioButton);
    }
    else
    {
      String str;
      if (paramFormat instanceof DecimalFormat)
      {
        str = ((DecimalFormat)paramFormat).toPattern();
        if ((str.startsWith("¤")) || (str.startsWith("$")))
        {
          this.currencyRadioButton.setSelected(true);
          applyRadioActionListener(this.currencyRadioButton);
        }
        else if (str.endsWith("%"))
        {
          this.percentRadioButton.setSelected(true);
          applyRadioActionListener(this.percentRadioButton);
        }
        else if (str.indexOf("E") > 0)
        {
          this.scientificRadioButton.setSelected(true);
          applyRadioActionListener(this.scientificRadioButton);
        }
        else
        {
          this.numberRadioButton.setSelected(true);
          applyRadioActionListener(this.numberRadioButton);
        }
        this.patternTextField.setText(str);
      }
      else if (paramFormat instanceof SimpleDateFormat)
      {
        str = ((SimpleDateFormat)paramFormat).toPattern();
        int i = isArrayContainPattern(Date_Array, str);
        if (i != -1)
        {
          this.dateRadioButton.setSelected(true);
          applyRadioActionListener(this.dateRadioButton);
        }
        else
        {
          i = isArrayContainPattern(Time_Array, str);
          if (i != -1)
          {
            this.timeRadioButton.setSelected(true);
            applyRadioActionListener(this.timeRadioButton);
          }
        }
        if (i != -1)
        {
          this.patternList.setSelectedIndex(i);
        }
        else
        {
          this.dateRadioButton.setSelected(true);
          applyRadioActionListener(this.dateRadioButton);
          this.patternTextField.setText(str);
        }
      }
      else if (paramFormat instanceof TextFormat)
      {
        this.textRadioButton.setSelected(true);
        applyRadioActionListener(this.textRadioButton);
      }
    }
  }

  public void onlyUseDatePane()
  {
    this.numberRadioButton.setEnabled(false);
    this.currencyRadioButton.setEnabled(false);
    this.scientificRadioButton.setEnabled(false);
    this.textRadioButton.setEnabled(false);
    this.percentRadioButton.setEnabled(false);
    this.nullRadioButton.setEnabled(true);
    this.dateRadioButton.setEnabled(true);
    this.timeRadioButton.setEnabled(true);
  }

  public void percentFormatPane()
  {
    this.nullRadioButton.setEnabled(false);
    this.numberRadioButton.setEnabled(false);
    this.currencyRadioButton.setEnabled(false);
    this.percentRadioButton.addActionListener(this.radioActionListener);
    this.scientificRadioButton.setEnabled(false);
    this.dateRadioButton.setEnabled(false);
    this.timeRadioButton.setEnabled(false);
    this.textRadioButton.setEnabled(false);
    this.percentRadioButton.setSelected(true);
    applyRadioActionListener(this.percentRadioButton);
  }

  private int isArrayContainPattern(String[] paramArrayOfString, String paramString)
  {
    for (int i = 0; i < paramArrayOfString.length; ++i)
      if (paramArrayOfString[i].equals(paramString))
        return i;
    return -1;
  }

  public Format update()
  {
    String str;
    if (this.nullRadioButton.isSelected())
      return null;
    if ((this.numberRadioButton.isSelected()) || (this.currencyRadioButton.isSelected()) || (this.percentRadioButton.isSelected()) || (this.scientificRadioButton.isSelected()))
    {
      str = this.patternTextField.getText();
      if ((str != null) && (str.length() > 0))
        try
        {
          DecimalFormat localDecimalFormat = new DecimalFormat(str);
          this.sampleLabel.setText(localDecimalFormat.format(DoubleValue));
          return localDecimalFormat;
        }
        catch (Exception localException1)
        {
          return new DecimalFormat("");
        }
      return new DecimalFormat("");
    }
    if ((this.dateRadioButton.isSelected()) || (this.timeRadioButton.isSelected()))
    {
      str = this.patternTextField.getText();
      if ((str != null) && (str.length() > 0))
        try
        {
          SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(this.patternTextField.getText());
          this.sampleLabel.setText(localSimpleDateFormat.format(new Date()));
          return localSimpleDateFormat;
        }
        catch (Exception localException2)
        {
          return new SimpleDateFormat("");
        }
      return new SimpleDateFormat("");
    }
    if (this.textRadioButton.isSelected())
      return TextFormat.getInstance();
    return null;
  }

  private void refreshPreviewLabel()
  {
    String str;
    this.sampleLabel.setText("" + DoubleValue);
    this.sampleLabel.setForeground(UIManager.getColor("Label.foreground"));
    if (this.nullRadioButton.isSelected())
      return;
    if ((this.numberRadioButton.isSelected()) || (this.currencyRadioButton.isSelected()) || (this.percentRadioButton.isSelected()) || (this.scientificRadioButton.isSelected()))
    {
      str = this.patternTextField.getText();
      if ((str != null) && (str.length() > 0))
        try
        {
          DecimalFormat localDecimalFormat = new DecimalFormat(str);
          this.sampleLabel.setText(localDecimalFormat.format(DoubleValue));
        }
        catch (Exception localException1)
        {
          this.sampleLabel.setForeground(Color.red);
          this.sampleLabel.setText(localException1.getMessage());
        }
    }
    else if ((this.dateRadioButton.isSelected()) || (this.timeRadioButton.isSelected()))
    {
      str = this.patternTextField.getText();
      if ((str != null) && (str.length() > 0))
        try
        {
          SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(this.patternTextField.getText());
          this.sampleLabel.setText(localSimpleDateFormat.format(new Date()));
        }
        catch (Exception localException2)
        {
          this.sampleLabel.setForeground(Color.red);
          this.sampleLabel.setText(localException2.getMessage());
        }
      else
        this.sampleLabel.setText(new Date().toString());
    }
    else if (this.textRadioButton.isSelected());
  }

  private void applyRadioActionListener(JRadioButton paramJRadioButton)
  {
    ActionEvent localActionEvent = new ActionEvent(paramJRadioButton, 100, "");
    this.radioActionListener.actionPerformed(localActionEvent);
  }

  public JLabel getSampleLabel()
  {
    return this.sampleLabel;
  }

  public void setSampleLabel(JLabel paramJLabel)
  {
    this.sampleLabel = paramJLabel;
  }

  static JTextField access$000(FormatPane paramFormatPane)
  {
    return paramFormatPane.patternTextField;
  }

  static JList access$100(FormatPane paramFormatPane)
  {
    return paramFormatPane.patternList;
  }

  static JRadioButton access$200(FormatPane paramFormatPane)
  {
    return paramFormatPane.nullRadioButton;
  }

  static JRadioButton access$300(FormatPane paramFormatPane)
  {
    return paramFormatPane.numberRadioButton;
  }

  static JRadioButton access$400(FormatPane paramFormatPane)
  {
    return paramFormatPane.currencyRadioButton;
  }

  static JRadioButton access$500(FormatPane paramFormatPane)
  {
    return paramFormatPane.percentRadioButton;
  }

  static JRadioButton access$600(FormatPane paramFormatPane)
  {
    return paramFormatPane.scientificRadioButton;
  }

  static JRadioButton access$700(FormatPane paramFormatPane)
  {
    return paramFormatPane.dateRadioButton;
  }

  static JRadioButton access$800(FormatPane paramFormatPane)
  {
    return paramFormatPane.timeRadioButton;
  }

  static JRadioButton access$900(FormatPane paramFormatPane)
  {
    return paramFormatPane.textRadioButton;
  }

  static Format access$1000(FormatPane paramFormatPane)
  {
    return paramFormatPane.format;
  }

  static void access$1100(FormatPane paramFormatPane)
  {
    paramFormatPane.refreshPreviewLabel();
  }
}